﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace pardusshipcalc
{
    public partial class SplashScreen : Form
    {
        int tickCount = 0;
        public SplashScreen()
        {
            InitializeComponent();

        }

        private void SplashScreen_Load(object sender, EventArgs e)
        {
            //Start off progress box
            progressTextBox.Text = "Pre-loading... " + tickCount.ToString() + "/10";

#if !MONO // Mono does not allow forms to spawn other forms in threads. Main form is launched via Program.cs instead.
            // Sets off the main form in its own thread while the splash is keeping the user occupied.
            Thread mainformthread = new Thread(loadmainform);
            mainformthread.SetApartmentState(ApartmentState.STA); // Prevents AS exception.
            mainformthread.Start();
#endif

           
            // No border on splash screen.
            this.FormBorderStyle = FormBorderStyle.None;

            // Version display
            labelVersionSplash.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
        }

        private void SplashScreen_KeyPress(object sender, KeyPressEventArgs e)
        {
            this.Close();
        }

        private void SplashScreen_MouseClick(object sender, MouseEventArgs e)
        {
            this.Close();
        }

        private void label3_MouseClick(object sender, MouseEventArgs e)
        {
            this.Close();
        }

        private void loadingPictureBox_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void labelVersionSplash_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void loadmainform()
        {
            // "dumb" thread. Just sets and runs. 
            MainForm mainForm = new MainForm();
            mainForm.ShowDialog();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            tickCount++;
            progressTextBox.Text = "Pre-loading... " + tickCount.ToString()+"/10";
			
			if (tickCount > 10)
			{
				this.Close();
			}
        }
    }
}
